package com.byzk.p2p.admin.bank.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.byzk.p2p.admin.bank.dao.BankCardDao;
import com.byzk.p2p.admin.bank.dto.Bank;
import com.byzk.p2p.admin.bank.dto.BankCard;
import com.byzk.p2p.admin.bank.vo.BankCardVo;
import com.byzk.p2p.admin.base.util.PageInfo;
import com.byzk.p2p.admin.money.dao.WithdrawDao;
import com.byzk.p2p.admin.money.vo.WithdrawRecordVo;

@Service
public class BankCardService {
	
	@Autowired
	private BankCardDao bankCardDao;
	
	@Autowired
	private WithdrawDao withdrawDao;
	
	public PageInfo<BankCardVo> listAll(BankCardVo vo){
		vo.setIsDelete(false);//未删除的银行卡
		int count=bankCardDao.count(vo);
		List<BankCardVo> voList=bankCardDao.listByPage( vo);
		PageInfo<BankCardVo> page=new PageInfo<BankCardVo>(count, vo.getIndex() , vo.getLimit());
		page.setPageList(voList);
		return page;
	}
	
	public List<BankCardVo> listDefaultCard(BankCardVo vo){
		return bankCardDao.listByPage( vo);
	}
	
	public BankCard getById(Integer id){
		return bankCardDao.getById(id);
	}
	
	public Integer saveOrUpdate(BankCard bankCard){
		if(bankCard.getId()==null){
			return bankCardDao.insert(bankCard);
		}else{
			return bankCardDao.update(bankCard);
		}
	}
	
	public Integer delete(Integer id){
		//逻辑删除
		return bankCardDao.delete(id);
	}
	
	public List<BankCard> listCardByUserId(Integer userId){
		return bankCardDao.listCardByUserId(userId);
	}
	
	public List<WithdrawRecordVo> listWithdrawById(Integer id){
		return withdrawDao.listWithdrawById(id);
	}
	
	public List<Bank> listBack(){
		return bankCardDao.bankList();
	}
	
	public BankCard selectBackByCardNo(String pBkAccNo){
		return bankCardDao.getBackByCardNo(pBkAccNo);
	}
	
	public Bank selectBackByCode(String code){
		return bankCardDao.getBackByCode(code);
	}
	
	public int deleteByUserId(Integer userId) {
		return bankCardDao.deleteByUserId(userId);
	}
}
